<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  
</body>
<script>
  //将用户输入的网址全部转化成我们的官网。如www.baidu.com=>www.lagou.com
  let str = 'www.baidu.com';
  const reg = /(\w+)\.(\w+)\.(\w+)/;

  var s1 = str.replace(reg, function(match,$1,$2,$3){
      console.log($1, $2, $3);
      return $1 + ".lagou." + $3 
    }); 

  console.log(s1);

</script>
</html>